package com.wenhai.disruptor;

import com.lmax.disruptor.BusySpinWaitStrategy;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;
import com.wenhai.disruptor.event.OrderEvent;
import com.wenhai.disruptor.pushlisher.OrderPublisher;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;

public class Main2 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService es = Executors.newFixedThreadPool(5);


        Disruptor<OrderEvent> disruptor =
                new Disruptor<>(OrderEvent::new, 1024, (ThreadFactory) Thread::new, ProducerType.MULTI, new BusySpinWaitStrategy());

        CountDownLatch countDownLatch = new CountDownLatch(1);
        disruptor.start();
        es.execute(() -> new OrderPublisher(countDownLatch, disruptor));
        countDownLatch.await();
        disruptor.shutdown();
    }
}
